using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Drawing.Imaging;
using UltimateDefend.Properties;

namespace UltimateDefend
{
    public abstract class ITree
    {
        #region fields
        protected Bitmap m_bmpTree;       //luu hinh anh hien thi cua tree
        protected Point m_pPosition;      //luu vi tri cua tree, la vi tri trung tam cua anh
        protected int m_iWidth;
        protected int m_iHeight;
        protected Rectangle m_rect;         //dien tich cua cay

        protected ImageAttributes m_imgAtt;
        #endregion fields

        #region properties
        public int Width
        {
            get { return this.m_iWidth; }
        }
        public int Height
        {
            get { return this.m_iHeight; }
        }
        #endregion properties

        #region methods

        /// <summary>
        /// ham de ve tree
        /// </summary>
        /// <param name="bmpBuff">bitmap can de ve tree len</param>
        /// <param name="pos">vi tri de ve tree</param>
        public void DrawTree(Bitmap bmpBuff, Point pos)
        {
            Graphics g = Graphics.FromImage(bmpBuff);
            //luu lai vi tri
            this.m_pPosition = pos;

            //ve cay len bitmap
            g.DrawImage(this.m_bmpTree,this.GetRect(pos), 0, 0, this.m_iWidth, this.m_iHeight, GraphicsUnit.Pixel, this.m_imgAtt);


            g.Dispose();
        }

        /// <summary>
        /// ham de ve tree va to mau nen cho tree, su dung khi build moi 1 tower
        /// </summary>
        /// <param name="bmpBuff">anh can ve len lai</param>
        /// <param name="bFillColor">co to nen hay khong
        /// true: neu muon to nen
        /// false: neu khong muon to nen</param>
        /// <param name="color">mau can to</param>
        public void DrawTree(Bitmap bmpBuff, bool bFillColor, Color color)
        {
            Graphics g = Graphics.FromImage(bmpBuff);
            if (bFillColor)
            {
                Brush brush = new SolidBrush(color);
                g.FillRectangle(brush, this.GetRect());
                brush.Dispose();
            }

            g.DrawImage(this.m_bmpTree, this.GetRect(), 0, 0, this.m_iWidth, this.m_iHeight, GraphicsUnit.Pixel, this.m_imgAtt);
                        
            g.Dispose();
        }



        /// <summary>
        /// ham lay ve dien tich cua 1 tree tinh tu 1 diem bat ky
        /// </summary>
        /// <param name="pos">diem truyen vao de tinh dien tich</param>
        /// <returns>dien tich cua tree chiem cho</returns>
        public Rectangle GetRect(Point pos)
        {
            return new Rectangle(pos.X - this.m_iWidth / 2, pos.Y - this.m_iHeight / 2, this.m_iWidth, this.m_iHeight);
        }

        /// <summary>
        /// ham lay ve dien tich cua 1 tree tinh tu vi tri tree do dang duoc xay dung
        /// </summary>
        /// <returns></returns>
        public Rectangle GetRect()
        {
            return new Rectangle(this.m_pPosition.X - this.m_iWidth / 2, this.m_pPosition.Y - this.m_iHeight / 2, this.m_iWidth, this.m_iHeight);
        }

        #endregion methods
    }

    public class TypeTree1 : ITree
    {
        public TypeTree1()
        {
            this.m_bmpTree = Resources.tree;
            this.m_iHeight = this.m_bmpTree.Height;
            this.m_iWidth = this.m_bmpTree.Width;

            this.m_imgAtt = new ImageAttributes();
            Color c = new Color();
            c = this.m_bmpTree.GetPixel(0, 0);
            this.m_imgAtt.SetColorKey(c, c);
                       
        }
    }
    public class TypeTree2 : ITree
    {
        public TypeTree2()
        {
            this.m_bmpTree = Resources.tree1;
            this.m_iHeight = this.m_bmpTree.Height;
            this.m_iWidth = this.m_bmpTree.Width;

            this.m_imgAtt = new ImageAttributes();
            Color c = new Color();
            c = this.m_bmpTree.GetPixel(0, 0);
            this.m_imgAtt.SetColorKey(c, c);
        }
    }
    public class TypeTree3 : ITree
    {
        public TypeTree3()
        {
            this.m_bmpTree = Resources.tree2;
            this.m_iHeight = this.m_bmpTree.Height;
            this.m_iWidth = this.m_bmpTree.Width;

            this.m_imgAtt = new ImageAttributes();
            Color c = new Color();
            c = this.m_bmpTree.GetPixel(0, 0);
            this.m_imgAtt.SetColorKey(c, c);
        }
    }
    public class TypeTree4 : ITree
    {
        public TypeTree4()
        {
            this.m_bmpTree = Resources.tree3;
            this.m_iHeight = this.m_bmpTree.Height;
            this.m_iWidth = this.m_bmpTree.Width;

            this.m_imgAtt = new ImageAttributes();
            Color c = new Color();
            c = this.m_bmpTree.GetPixel(0, 0);
            this.m_imgAtt.SetColorKey(c, c);
        }
    }
    public class TypeTree5 : ITree
    {
        public TypeTree5()
        {
            this.m_bmpTree = Resources.tree4;
            this.m_iHeight = this.m_bmpTree.Height;
            this.m_iWidth = this.m_bmpTree.Width;

            this.m_imgAtt = new ImageAttributes();
            Color c = new Color();
            c = this.m_bmpTree.GetPixel(0, 0);
            this.m_imgAtt.SetColorKey(c, c);
        }
    }
    public class TypeTree6 : ITree
    {
        public TypeTree6()
        {
            this.m_bmpTree = Resources.rock;
            this.m_iHeight = this.m_bmpTree.Height;
            this.m_iWidth = this.m_bmpTree.Width;

            this.m_imgAtt = new ImageAttributes();
            Color c = new Color();
            c = this.m_bmpTree.GetPixel(0, 0);
            this.m_imgAtt.SetColorKey(c, c);
        }
    }
   
}
